@inherits MasaComponentBase
@{
    var buttonColor = DisabledButton ? "#A3AED0" : "#323D6F";
    var content = ConfigObject.Content.Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "");
    var tempContent = ConfigObject.TempContent.Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "");
}

<div class="emphasis--text h6 d-flex align-center">
    <MRow NoGutters class="align-center">
        <MCol Cols="12" class="d-flex align-center">
            @if (ConfigObject.FromRelation)
            {
                <SIcon Color="primary" Class="mr-2">mdi-link-variant</SIcon>
            }
            @if (ConfigObject.Encryption)
            {
                <SIcon Style="pointer-events: auto !important;" Color="#323D6F" Tooltip="@T("Encrypted config object")" Size="18" Class="mr-2">mdi-lock</SIcon>
            }
            <MHover Context="hContext">
                <div @attributes="hContext.Attrs" class="hover-pointer d-flex align-center">
                    <span class="mr-2">@ConfigObject.Name</span>
                    <div @onclick="() => Copy(ConfigObject.Name)" @onclick:stopPropagation>
                        <SIcon Tooltip="@T("Copy name")"
                               Color="@(_configNameCopyClicked ? "success" : "gray")"
                               Style="@(hContext.Hover ? "width: 18px; height: 18px; margin-right: 12px; transition: 0.5s;" : "opacity:0; width: 18px; height: 0px; margin-left: -24px; transition: 0.4s;")">
                            @(_configNameCopyClicked ? _checkSvg : _copySvg)
                        </SIcon>
                    </div>
                </div>
            </MHover>
            <div class="regular3--text btn d-flex">
                <span>|</span>
                <sapn class="ml-2">@ConfigObject.FormatName</sapn>
            </div>
        </MCol>
        <MCol Cols="12" class="d-flex" Style="font-size: 0.75rem; font-weight: 400;">
            @if (ConfigObject is { RelationConfigObjectId: 0, IsPublished: false } && content != tempContent)
            {
                <div class="mr-2 d-flex align-center" style="height: 24px; padding:0 6px; background: #FF7D00;min-width:44px;text-align: center;color: white; border-radius: 6px;line-height: 18px;">
                    @T("Modified")
                </div>
            }
            @if (ShowPublish)
            {
                <div class="mr-2 d-flex align-center" style="height: 24px; padding:0;line-height: 18px;">
                    <LatestConfigPublish LatestReleaseConfigModel="ConfigObject.LatestRelease" TitleClass="mr-1 regular3--text body3" TextClass="regular3--text body3"></LatestConfigPublish>
                </div>
            }
        </MCol>
    </MRow>
    <MSpacer></MSpacer>
    @if (FormatLabelCode == "properties")
    {
        if (!ConfigObject.FromRelation)
        {
            <SButton Disabled="DisabledButton" OnClickStopPropagation Icon Class="mr-4" OnClick="UpdateConfig">
                <SIcon Tooltip="@(T("Add config item"))" Color="@buttonColor">mdi-plus-circle</SIcon>
            </SButton>
        }
    }
    else
    {
        if (ConfigObject.IsEditing)
        {
            <SButton Class="mr-4" OnClickStopPropagation Icon OnClick="CancelEditConfig">
                <SIcon Tooltip="@T("Cancel")" Color="#323D6F">mdi-close-thick</SIcon>
            </SButton>
        }

        <SButton OnClickStopPropagation Icon Class="mr-4" OnClick="UpdateConfig">
        @if (!ConfigObject.IsEditing)
            {
                var relation = ConfigObject.RelationConfigObjectId != 0;
                <SIcon Tooltip="@(relation ? T("UnConnected") : T("Edit"))" Color="#323D6F">@(relation ? "mdi-link-variant-off" : "mdi-pencil")</SIcon>
            }
            else
            {
                <SIcon Tooltip="@(T("Save"))" Color="success">mdi-check</SIcon>
            }
        </SButton>
    }
    @if (EnableClone && !ConfigObject.FromRelation)
    {
        <SButton Disabled="DisabledButton" OnClickStopPropagation Icon Class="mr-4" OnClick="CloneConfig">
        <SIcon Tooltip="@T("Clone")" Size="20" Color="@buttonColor">fa:fas fa-copy</SIcon>
        </SButton>
    }
    <SButton Disabled="DisabledButton" OnClickStopPropagation Icon Class="mr-4" OnClick="ReleaseConfig">
        <SIcon Tooltip="@T("Release")" Color="@buttonColor">mdi-send</SIcon>
    </SButton>
    <MMenu OffsetY NudgeLeft="72" Attach="@true" ContentClass="menu-configmore">
        <ActivatorContent>
            <SButton Disabled="DisabledButton" @attributes="@context.Attrs" OnClickStopPropagation Icon Class="mr-4">
                <SIcon Color="@buttonColor">mdi-dots-vertical</SIcon>
            </SButton>
        </ActivatorContent>
        <ChildContent>
            <MList Width="180" Class="pa-2" __internal_stopPropagation_onclick>
                <MListItem OnClick="ReleaseHistory">
                    <SIcon Class="mr-4" IsDefaultToolTip="false">mdi-history</SIcon>
                    <MListItemContent>
                        <MListItemTitle>@T("Release history")</MListItemTitle>
                    </MListItemContent>
                </MListItem>
                <MListItem OnClick="Rollback">
                    <SIcon Class="mr-4" IsDefaultToolTip="false">mdi-repeat</SIcon>
                    <MListItemContent>
                        <MListItemTitle>
                            @T("Rollback")
                        </MListItemTitle>
                    </MListItemContent>
                </MListItem>
                <MListItem OnClick="RevokeAsync">
                    <SIcon Class="mr-4" IsDefaultToolTip="false">mdi-subdirectory-arrow-left</SIcon>
                    <MListItemContent>
                        <MListItemTitle>
                            @T("Revoke")
                        </MListItemTitle>
                    </MListItemContent>
                </MListItem>
                <MDivider></MDivider>
                <MListItem OnClick="RemoveAsync">
                    <SIcon Class="mr-4" Color="error" IsDefaultToolTip="false">mdi-delete</SIcon>
                    <MListItemContent>
                        <MListItemTitle Class="error--text">
                            @T("Delete")
                        </MListItemTitle>
                    </MListItemContent>
                </MListItem>
            </MList>
        </ChildContent>
        </MMenu>
        @if (!Disabled)
    {
        <MDivider Vertical Class="separator"></MDivider>
    }
</div>